package com.fjwt.gz.proxy.ctrl.activity;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.entity.ActivityTypeEntity;
import com.fjwt.gz.proxy.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.ActivityTypeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 活动类型
 *
 */
@RestController
@Slf4j
@RequestMapping("/api/activity/type")
public class ActivityTypeController extends CommonCtrl {

    @Autowired
    private ActivityTypeService activityTypeService;

    /**
     * 查询活动类型列表
     * @return
     */
    @GetMapping
    public ApiRes list() {
        ActivityTypeEntity activityTypeEntity = getObject(ActivityTypeEntity.class);
        LambdaQueryWrapper<ActivityTypeEntity> queryWrapper = ActivityTypeEntity.gw();
        queryWrapper.like(StringUtils.isNotEmpty(activityTypeEntity.getActivityTypeName()),
                        ActivityTypeEntity::getActivityTypeName, activityTypeEntity.getActivityTypeName())
                .orderByDesc(ActivityTypeEntity::getCreatedAt);
        IPage<ActivityTypeEntity> page = activityTypeService.page(getIPage(true), queryWrapper);
        return ApiRes.page(page);
    }

}
